import request from "../../utils/request";

// pages/index/index.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        bannerList:[],//轮播图
        recommendList:[],//推荐歌单
        topList:[],//排行榜
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: async function (options) {
        let bannerListData=await request('/banner',{type:2})
        this.setData({
            bannerList:bannerListData.banners
        });
        let recommendListData=await request('/personalized',{limit:10})
        this.setData({
            recommendList:recommendListData.result
        });

        let index=0
        let topArr=[]
        while (index < 5){
            let topListData=await request('/toplist/detail')
            let topListId={id:topListData.list[index].id}
            let topListResult=await request('/playlist/detail',{id:topListId.id})
            let topListItem={name:topListResult.playlist.name,tracks:topListResult.playlist.tracks.slice(0,3)}
            index++
            topArr.push(topListItem)
            this.setData({
                topList:topArr
            })
        }

    },

    toRecommend(){
        wx.navigateTo({
            url:'/pages/recommendSong/recommendSong'
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})